const path = require('path')
const webpack = require('webpack')
const fs = require('fs')
const host = 'http://39.98.220.70:10010/'

function resolve(dir) {
  return path.resolve(__dirname, dir)
}

let config = {
  // configureWebpack: config => {
    // config.plugins = [
    //   new webpack.ProvidePlugin({
    //     $: "jquery",
    //     jQuery: "jquery",
    //     "windows.jQuery": "jquery"
    //   })
    // ]
  //   config.cacheBusting = false,
  //   config.devtool = 'eval-source-map'
  // },

  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      })
    ],
    
    externals: {
        'BMap': 'BMap'
    },

  },

  productionSourceMap: false,

  chainWebpack: config => {
    config.resolve.alias
      .set('vue$', 'vue/dist/vue.esm.js')
      .set('@', resolve('src'))
      .set('src', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('services', resolve('src/services'))
      .set('utils', resolve('src/utils'))
      .set('scss_vars', '@/styles/vars.scss')
  },
}

if (process.env.NODE_ENV === 'production') {
  config = {

    ...config,

    baseUrl: './',

    // outputDir: 'dist',

    // assetsDir: 'static',

    // filenameHashing: true,


    pages: {
      index: {
        // entry for the page
        entry: 'src/main.js',
        // the source template
        template: 'public/index.html',
        favicon: 'public/favicon.ico',
        // output as dist/index.html
        // filename: resolve('../../../api/application/agent/view/index/index.html'),
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: 'hj-cloud'
      },
    },
  }
} else { // 开发环境配置
  config = {
    ...config,

    devServer: {
      // publicPath: '/',
      port: 8081,
      open: true,
      historyApiFallback: true,
      allowedHosts: [
        // 'agent.shield.com',
        'localhost',
      ],
      proxy: {
        "itsu11": {
          target: host,
          secure: false,
          changeOrigin: false
        }
      },
    },
    // baseUrl: '/',

    // outputDir: resolve('./devdist'),

  }
}
module.exports = config